home *** CD-ROM | disk | FTP | other *** search
/ Chip 2001 December / Chip Aralık 2001.iso / prog / office / f_0259 / Common.xba < prev    next >
Encoding:
Extensible Markup Language  |  2001-07-30  |  7.8 KB  |  259 lines

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!DOCTYPE script:module PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "module.dtd">
  3. <script:module xmlns:script="http://openoffice.org/2000/script" script:name="Common" script:language="StarBasic"> REM  *****  BASIC  *****
  4. Public DialogModel as Object
  5. Public DialogConvert as Object
  6. Public DialogPassword as Object
  7. Public PasswordModel as Object
  8.  
  9. Sub    RetrieveDocumentObjects()
  10.     CurMimeType = oDocument.DocumentInfo.MimeType
  11.     If Instr(1, CurMimeType, "calc") <> 0 Then
  12.         oSheets = oDocument.Sheets
  13.         oSheet = oDocument.Sheets.GetbyIndex(0)
  14. '        oAddressRanges = oDocument.createInstance("com.sun.star.sheet.SheetCellRanges")
  15.     End If
  16.     oStatusline = oDocument.GetCurrentController.GetFrame.CreateStatusIndicator
  17.     ' Retrieve the indices for the cellformatations
  18.     oFormats = oDocument.NumberFormats
  19. End Sub    
  20.  
  21.  
  22. Sub CloseDialog
  23. Dim n, m as Integer
  24.     If Not bMacroStopped Then
  25.         bMacroStopped = True
  26.         DialogConvert.EndExecute
  27.         If Not DocDisposed Then
  28.             ReprotectSheets()    
  29.         End If
  30.         Stop
  31.     End If
  32. End Sub
  33.  
  34.  
  35. Function ConvertDocument()
  36.     GoOn = True
  37.     DocDisposed = True
  38.     InitializeProgressbar()    
  39.     If Instr(1, CurMimeType, "calc") <> 0 Then
  40.         bDocHasProtectedSheets = CheckSheetProtection(oSheets)
  41.         If bDocHasProtectedSheets Then
  42.             bDocHasProtectedSheets = UnprotectSheetsWithPassword(oSheets, bDoUnProtect)
  43.         End If
  44.         If Not bDocHasProtectedSheets Then
  45.             If Not bRangeListDefined Then
  46.                 TotCellCount = 0
  47.                 CreateRangeEnumeration(True)    
  48.             Else
  49.                 IncreaseStatusvalue(SBRelGet/3)
  50.             End If
  51.             RangeIndex = Ubound(RangeList(), 1)
  52.             If RangeIndex > -1 Then
  53.                 ConvertThehardWay(RangeList(), True, False)
  54.                 MakeStyleEnumeration(True)
  55.                 oDocument.calculateAll()
  56.             End If
  57.             ReprotectSheets()
  58.             bRangeListDefined = False
  59.         End If
  60.     Else
  61.         oStatusline.SetValue(10)
  62.         ConvertTextFields()
  63.         oStatusline.SetValue(80)
  64.         ConvertWriterTables()
  65.     End If    
  66.     oStatusline.End
  67.     On Local Error Goto 0 
  68. End Function
  69.  
  70.  
  71. Sub SwitchNumberFormat(oObject as Object, oFormats as object, sNewSymbol as String)
  72. Dim nFormatLanguage as Integer
  73. Dim nFormatDecimals as Integer
  74. Dim nFormatLeading as Integer
  75. Dim bFormatLeading as Integer
  76. Dim bFormatNegRed as Integer
  77. Dim bFormatThousands as Integer
  78. Dim aLocLocale As New com.sun.star.lang.Locale
  79. Dim i as Integer
  80. Dim aNewStr as String
  81. Dim iNumberFormat as Long
  82. Dim AddToList as Boolean
  83.  
  84.     ' Numberformat mit dem neuen Symbol als Basis f├╝r generateFormat
  85.     aSimpleStr = "0 [$"+sNewSymbol+"]"
  86.     nSimpleKey = Numberformat(oFormats, aSimpleStr, oLocale)
  87.     On Local Error Resume Next
  88.     iNumberFormat = oObject.NumberFormat
  89.     If Err <> 0 Then
  90.         Msgbox "Error Reading the Number Format"
  91.         Resume CLERROR
  92.     End If
  93.  
  94.     On Local Error GoTo NOKEY
  95.     aFormat() = oFormats.getByKey(iNumberFormat)
  96.     On Local Error GoTo 0
  97.     ' Typ und W├ñhrungssymbol des Numberformats heraussuchen
  98.     ' neues W├ñhrungsformat mit passenden Einstellungen setzen
  99.     nFormatDecimals = aFormat.Decimals
  100.     nFormatLeading = aFormat.LeadingZeros
  101.     bFormatNegRed = aFormat.NegativeRed
  102.     bFormatThousands = aFormat.ThousandsSeparator
  103.     aLocLocale = aFormat.Locale
  104.     aNewStr = oFormats.generateFormat( nSimpleKey, oLocale, _
  105.             bFormatThousands, bFormatNegRed, nFormatDecimals, nFormatLeading)
  106.     
  107.     oObject.NumberFormat = Numberformat(oFormats, aNewStr, aLocLocale)
  108.     NOKEY:
  109.     If Err <> 0 Then
  110.         Resume CLERROR
  111.     End If
  112.     CLERROR:
  113. End Sub
  114.  
  115.  
  116. Function Numberformat( oFormats as Object, aFormatStr as String, oLocale as Object)
  117. Dim nRetkey 
  118.     nRetKey = oFormats.queryKey( aFormatStr, oLocale, True )
  119.     If nRetKey = -1 Then
  120.         nRetKey = oFormats.addNew( aFormatStr, oLocale )
  121.         If nRetKey = -1 Then nRetKey = 0
  122.     End If
  123.     Numberformat = nRetKey
  124. End Function
  125.  
  126.  
  127. ' Funktion findet den Formattyp einer Vorlage, Zelle oder eines Bereiches heraus und schreibt das Ergebnis
  128. ' in die globale Variable nFormatType; Ist ein W├â┬ñhrungssymbol gesetzt, wird dieses in den globalen String
  129. ' sFormatCurrency geschrieben.
  130. Function CheckFormatType( FormatObject as object)
  131. Dim i as Integer
  132. Dim LocCurrIndex as Integer
  133. Dim nFormatFormatString as String
  134. Dim FormatLangID as Integer
  135. Dim sFormatCurrExt as String
  136. Dim oFormatofObject() as Object
  137.  
  138.     ' Retrieve the Format of the Object
  139.     On Local Error GoTo NOKEY
  140.     oFormatofObject = oFormats.getByKey(FormatObject.NumberFormat)
  141.     On Local Error GoTo 0            
  142.     ' Typ und W├â┬ñhrungssymbol des Numberformats heraussuchen
  143.       If NOT INT(oFormatofObject.Type) AND com.sun.star.util.NumberFormat.CURRENCY Then
  144.         CheckFormatType = False
  145.         Exit Function
  146.     End If
  147.  
  148.     If FieldinArray(CurrSymbolList(),2,oFormatofObject.CurrencySymbol) Then
  149.         ' If the Currencysymbol of the object ist the one needed, then check the Currency extension
  150.         sFormatCurrExt = oFormatofObject.CurrencyExtension
  151.  
  152.         If FieldInList(CurExtension(),1,sFormatCurrExt) Then
  153.             ' The Currency - extension also fits
  154.             CheckFormatType = True
  155.         Else
  156.             ' The Currency - symbol is Euro-conforming (like 'DEM'), so there is no Currency-Extension
  157.             CheckFormatType = oFormatofObject.CurrencySymbol = CurrsymbolList(2)
  158.         End If
  159.     Else
  160.         ' The Currency Symbol of the object is not the desired one
  161.         If oFormatofObject.CurrencySymbol = "" Then
  162.             ' Format is "automatic"
  163.             CheckFormatType = CheckLocale(oFormatofObject.Locale)
  164.         Else
  165.             CheckFormatType = False
  166.         End If
  167.     End If
  168.  
  169.     NOKEY:
  170.     If Err <> 0 Then
  171.         CheckFormatType = False
  172.         Resume CLERROR
  173.     End If
  174.     CLERROR:
  175. End Function
  176.  
  177.  
  178. Sub StartConversion()
  179.     GoOn = True
  180. '    ToggleWindow(False)
  181.     Select Case DialogModel.Step
  182.         Case 1
  183.             If DialogModel.chkComplete.State = 1 Then
  184.                 ConvertWholeDocument()
  185.             Else
  186.                 ConvertRangesorStylesofDocument()
  187.             End If
  188.         Case 2
  189.             InitializeThirdStep()
  190.             ConvertDocuments()
  191.         Case 3
  192.             CloseDialog()
  193.  
  194.     End Select
  195. End Sub
  196.  
  197.  
  198. Sub IncreaseStatusValue(AddStatusValue as Integer)
  199.     StatusValue = Int(StatusValue + AddStatusValue)
  200.     oStatusline.SetValue(StatusValue)
  201. End Sub
  202.  
  203.  
  204. Sub SelectCurrency()
  205. Dim AddtoList as Boolean
  206. Dim UpRangeList as Integer
  207. Dim OldCurrIndex as Integer
  208.     OldCurrIndex = CurrIndex
  209.     CurrIndex = DialogModel.lstCurrencies.SelectedItems(0)
  210.     InitializeCurrencyValues(CurrIndex)
  211.     CurExtension(0) = LangIDValue(CurrIndex,0,2)
  212.     CurExtension(1) = LangIDValue(CurrIndex,1,2)
  213.     If DialogModel.Step = 1 Then
  214.         If OldCurrIndex = -1 Then
  215.             DialogModel.chkComplete.State = 1
  216.             EnableStep1DialogControls(True,False, True)
  217.             SetOptionValuestoNull()
  218.         Else
  219.             EnableStep1DialogControls(False,False, False)
  220.             If DialogModel.optCellTemplates.State = 1 Then
  221.                 EnableStep1DialogControls(False, False, False)
  222.                 CreateStyleEnumeration()
  223.                 EnableStep1DialogControls(True, True, True)
  224.             ElseIf ((DialogModel.optSheetRanges.State = 1) OR (DialogModel.optDocRanges.State = 1)) AND (DialogModel.Step = 1) Then
  225.                 UpRangeList = UBound(RangeList())
  226.                 ReDim RangeList(UpRangeList) 'as String
  227.                 CreateRangeEnumeration(False)
  228.             ElseIf DialogModel.optSelRange.State= 1 Then
  229.                 'Preselected Range
  230.                 CheckRangeSelection()
  231.             End If
  232.             EnableStep1DialogControls(True, True, True)
  233.         End If
  234.     ElseIf DialogModel.Step = 2 Then
  235.         EnableStep2DialogControls(True)
  236.     End If
  237. End Sub
  238.  
  239.  
  240. Sub FillUpCurrencyListbox()
  241. Dim i as Integer
  242. Dim MaxIndex as Integer
  243.     MaxIndex = Ubound(CurrValue(),1)
  244.     Dim LocList(MaxIndex) as String
  245.     For i = 0 To MaxIndex
  246.         LocList(i) = CurrValue(i,0)
  247.     Next i
  248.     DialogModel.lstCurrencies.StringItemList() = LocList()
  249.     If CurrIndex > -1 Then
  250.         SelectListboxItem(DialogModel.lstCurrencies, CurrIndex)
  251.     End If
  252. End Sub
  253.  
  254.  
  255. Sub InitializeProgressbar()
  256.     CurCellCount = 0
  257.     oStatusline.Start(sStsPROGRESS,100)             '"Konvertierungsfortschritt:"
  258.     StatusValue = 0
  259. End Sub</script:module>